

#include"SyncQueue_2.hpp"
#include"FixedThreadPool.hpp"
#include<iostream>
#include"Timer.hpp"
#include"TimerManage.hpp"
//#include<latch>

using namespace std;

static int x=0;
void funa(){

    cout<<"funa::x:"<<x++<<endl;
}
void funb(){
    cout<<"funb::x:"<<x++<<endl;
}
void func(){
    cout<<"func::x:"<<x++<<endl;
}

int main()
{
    zhb::TimerMap tm;
    zhb::Timer tv1, tv2, tv3;
    tm.init(-1);

    tv1.init();
    tv2.init();
    tv3.init();

    tv1.set_timer(funa,300);
    tv2.set_timer(funb,500);
    tv3.set_timer(func,1000);
    
    tm.add_timer(tv1);
    tm.add_timer(tv2);
    tm.add_timer(tv3);

    std::this_thread::sleep_for(std::chrono::seconds(100));

    return 0;
}

#if 0

//std::latch tag(3);

class m_latch   //门闩
{
    private:
    std::atomic_int count_;
    std::mutex mtx_;
    std::condition_variable cond_;
    public:
    m_latch(int num=1):count_(num){}
    void count_down(){
        std::lock_guard<std::mutex>lock(mtx_);
        if(--count_==0){cond_.notify_all();}
    }
    void wait(){
        std::unique_lock<std::mutex>lock(mtx_);
        while(count_!=0){
            cond_.wait(lock);
        }
    }


};

m_latch tag(3);

void funa(){
    cout<<"funa"<<endl;
    tag.count_down();

}
void funb(int x){
    cout<<"funb:"<<x<<endl;
    tag.count_down();
    
    }

class Bar{
    int value;
    public:
    Bar(int x=0):value(x){}
    void func(int x){cout<<"Bar::func"<<"x="<<x<<"value="<<value<<endl;
    tag.count_down();
    }
};

int main()
{
    zhb::FiexdThreadPool t(6);
    Bar bar(10);
    t.AddTask(funa);
    t.AddTask(std::bind(funb,20));
    t.AddTask(std::bind(&Bar::func,&bar,30));

    tag.wait();
    //std::this_thread::sleep_for(std::chrono::seconds(5));
    return 0;
}

#endif